﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

using FlickrPortfolio.Helpers;
using FlickrPortfolio.Models.Services.Interfaces;

using FlickrNet;

using FlickrPortfolio.DataAccess;

namespace FlickrPortfolio.Models.Services {
    public class PhotoService : IPhotoService {
        private readonly DataAccess.Flickr flickr = new DataAccess.Flickr();

        public IList<Photo> GetPhotos() {
            IList<FlickrNet.Photo> flickrPhotos = flickr.GetPhotos()
                .Where(x => !x.MachineTags.Contains("Portfolio:Show=False"))
                .Where(x => !x.MachineTags.Contains("Portfolio:Show=No"))
                .Where(x => !x.MachineTags.Contains("Portfolio:Hide=True"))
                .Where(x => !x.MachineTags.Contains("Portfolio:Hide=Yes"))
                .ToList();

            IList<Photo> myPhotos = new List<Photo>();

            foreach (var flickrPhoto in flickrPhotos) {
                myPhotos.Add(new Photo(flickrPhoto));
            }

            return myPhotos;
        }

        public Photo GetPhoto(string id) {
            var flickrPhoto = flickr.GetPhoto(id);

            if (flickrPhoto.Owner.UserId != AppHelper.GetUserID())
                throw new Exception("Photo does not belong to this user");

            var myPhoto = new Photo(flickrPhoto);
            return myPhoto;
        }

        public IList<Tag> GetPhotosByTag(string id) {
            throw new NotImplementedException();
        }
    }
}